<?php
// +----------------------------------------------------------------------
// | 评论/留言模型
// +----------------------------------------------------------------------
// | @link
// +----------------------------------------------------------------------
// | @copyright
// +----------------------------------------------------------------------
// | @licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | @author Haijun Wu <nicholasinlove@126.com>
// +----------------------------------------------------------------------
// | $Id: CommentModel.class.php 78 2011-03-30 10:46:16Z nicholasinlove1986@gmail.com $
// +----------------------------------------------------------------------


class CommentModel extends Model {

	protected $_validate	 =	 array(
		array('comment_author','require','错误：请填写必要信息（姓名和电子邮件）。',1),
		array('comment_email','require','错误：请填写必要信息（姓名和电子邮件）。',1),
		array('comment_email','email','错误：请输入一个有效的电子邮件地址。',1),
		//array('comment_url','url','错误：请输入一个有效的URL地址（http://）。',0),
		array('comment_content','require','错误：请输入留言内容。',1),
	);
	
	protected $_auto	 =	 array(
		array('comment_addtime','time',1,'function'),
		array('comment_visible','1',1),
		array('comment_approved','0',1),
		array('comment_url','fillAuthorWebsite',1,'callback'),
	);
		
	/* 如果留言用户的链接地址没有http://，补上 */
	protected function fillAuthorWebsite() {
		if (strpos($_POST['comment_url'], 'http://') === false && strpos($_POST['comment_url'], 'https://') === false) {
			$_POST["comment_url"] = 'http://' . trim($_POST['comment_url']);
		}
		if (!preg_match('/^https?:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/',$_POST["comment_url"])) {
			return "";
		} else {
			return $_POST["comment_url"];
		}
	}
	
}

?>